function getIn(target:any, keyPath:any, notFoundValue = undefined) {
  let key;
  for (let i = 0; i < keyPath.length; i++) {
    key = keyPath[i];
    // eslint-disable-next-line no-prototype-builtins
    if (target && target.hasOwnProperty(key)) {
      target = target[key];
    } else {
      return notFoundValue;
    }
  }

  return target;
}

function get(target:any, keyPathStr:any, notFoundValue:any = undefined) {
  return getIn(target, keyPathStr.split('.'), notFoundValue);
}

export default get;
